<template>
  <span @click="check()">
    <slot />
  </span>
</template>

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator'
import { State } from 'vuex-class'

@Component({
  name: 'OAuthCheckLogin'
})
export default class Com extends Vue {
  @State('oauth') OAuth: any;

  check (isReturn = false) {
    if (this.OAuth.name) {
      if (isReturn) {
        return true
      } else {
        this.$emit('success')
      }
    } else {
      this.$confirm({
        title: '登录提示',
        content: '请先登录',
        onOk: () => {
          this.toOAuth()
        }
      })
    }
  }

  toOAuth () {
    this.$router.push({
      path: '/OAuth',
      query: {
        webBack: this.$route.path
      }
    })
  }
}
</script>

<style scoped lang="less">

</style>
